package com.moinut.studentattendancemanager.controller;

import com.moinut.studentattendancemanager.controller.callback.OnGetListListener;
import com.moinut.studentattendancemanager.model.factory.DAOFactory;
import com.moinut.studentattendancemanager.model.vo.CourseInfo;
import com.sun.istack.internal.NotNull;

import java.util.List;

/**
 * @author MOILING
 */
public class ComboItemController {

    public static void getAllCourse(@NotNull OnGetListListener<CourseInfo> listener) {
        try {
            List<CourseInfo> courses = DAOFactory.getICourseInfoDAOInstance().getAllClass();
            if (courses.size() > 0) {
                listener.onSuccess(courses);
            } else {
                listener.onError("没找到课程信息");
            }
        } catch (Exception e) {
            e.printStackTrace();
            listener.onError(e.getMessage());
        }
    }

    public static void getCourseByTeacherId(@NotNull String teacherId, @NotNull OnGetListListener<CourseInfo> listener) {
        try {
            List<CourseInfo> courses = DAOFactory.getICourseInfoDAOInstance().getClassByTeacherId(teacherId);
            if (courses.size() > 0) {
                listener.onSuccess(courses);
            } else {
                listener.onError("没找到课程信息");
            }
        } catch (Exception e) {
            e.printStackTrace();
            listener.onError(e.getMessage());
        }
    }

    public static void getAllCollegeNames(@NotNull OnGetListListener<String> listener) {
        try {
            List<String> names = DAOFactory.getICollegeDAOInstance().getAllCollegeName();
            if (names.size() > 0) {
                listener.onSuccess(names);
            } else {
                listener.onError("没找专业信息");
            }
        } catch (Exception e) {
            e.printStackTrace();
            listener.onError(e.getMessage());
        }
    }

    public static void getAllFacultyNames(@NotNull OnGetListListener<String> listener) {
        try {
            List<String> names = DAOFactory.getIFacultyDAOInstance().getAllFacultyName();
            if (names.size() > 0) {
                listener.onSuccess(names);
            } else {
                listener.onError("没找教研室信息");
            }
        } catch (Exception e) {
            e.printStackTrace();
            listener.onError(e.getMessage());
        }
    }
}
